export default {
    bind: function (el, binding) {
        el.addEventListener('load', function () {
                // 创建一个canvas元素
                const canvas = document.createElement('canvas');
                canvas.width = el.width;
                canvas.height = el.height;
                const ctx = canvas.getContext('2d');

                // 绘制水印文本
                ctx.font = '30px Arial';
                ctx.fillStyle = 'rgba(0,0,0,0.2)';
                ctx.textAlign = 'center';
                ctx.fillText(binding.value, canvas.width / 2,canvas.width , canvas.height);

                // 将canvas中的内容绘制到图片上
                ctx.drawImage(el, 0, 0);

                // 替换原始图片
                el.src = canvas.toDataURL('image/jpeg');
            })

        }
    }